﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ExplorerPlus.PersistenceLayer.Xml;

namespace ExplorerPlus.UnitTest
{
    class PersistenceLayerTest
    {
        public void RunTest()
        {
            Repository xml = new Repository("books");
            Metadata meta = xml.LoadMetadata();

            if (meta.Field.Rows.Count == 0)
            {
                meta.Field.AddFieldRow(1, "Author", "string", true);
                meta.Field.AddFieldRow(2, "Category", "string", true);
                meta.Field.AddFieldRow(3, "ISBN", "string", false);
                meta.Field.AddFieldRow(4, "Publisher", "string", true);
                meta.Field.AddFieldRow(5, "Rating", "string", false);
                meta.Field.AddFieldRow(6, "TotalCustomerReviews", "string", false);
                meta.Field.AddFieldRow(7, "SalesRank", "string", false);
                meta.Field.AddFieldRow(8, "DetailPageUrl", "string", false);
                meta.Field.AddFieldRow(9, "EditorialReviews", "string", false);
                meta.Field.AddFieldRow(10, "NoOfPages", "int", false);
                meta.Field.AddFieldRow(11, "PublicationDate", "string", false);
                meta.Field.AddFieldRow(12, "Edition", "int", false);
                meta.Field.AddFieldRow(13, "ListPrice", "decimal", false);
                meta.Field.AddFieldRow(14, "LargeImage", "string", false);
                meta.Field.AddFieldRow(15, "SmallImage", "string", false);

                meta.Plugin.AddPluginRow("ExplorerPlus.Plugins.Books.dll", "ExplorerPlus.Plugins.Books.dll", "ExplorerPlus.Plugins.Books.dll", "ExplorerPlus.Plugins.Books.dll");

                xml.UpdateMetadata(meta);
            }

            Console.WriteLine("FieldId\tFieldName\tFieldType\tIsSearchable");
            
            foreach (Metadata.FieldRow row in meta.Field.Rows)
            {
                Console.WriteLine("{0}\t{1}\t{2}\t{3}", row.FieldId, row.FieldName, row.FieldType, row.IsSearchable);
            }

        }
    }
}
